#include <iostream>
using namespace std;

#define MAX 10

// 【题目276】设计一个模板类Sample，用于对-一个有序数组采用二分法查找元素下标。

class Sample
{
private:
    int a[MAX];

public:
    Sample()
    {
        for (int i = 0; i < MAX; i++)
        {
            a[i] = i;
        }
    }

    int seek(int x)
    {
        int low = 0, high = MAX - 1;
        while (low <= high)
        {
            int mid = (low + high) / 2;
            if (x == a[mid])
            {
                return mid;
            }
            else if (x < a[mid])
            {
                high = mid - 1;
            }
            else
            {
                low = mid + 1;
            }
        }
        return -1;
    }
};

int main()
{
    Sample s;
    cout << s.seek(5) << endl;
    return 0;
}